package com.william.jdbcplus.generator;

import com.william.jdbcplus.core.dialects.ddl.DDLUtil;
import com.william.jdbcplus.core.util.JdbcUtil;
import com.william.jdbcplus.generator.entity.*;

import javax.sql.DataSource;

/**
 * 自动生成数据库结构
 */
public class DbGeneratorUtil {
    public static DataSource getDs() {
        return getMysql();
    }

    public static DataSource getMysql() {
        String url = "jdbc:mysql://192.168.0.98:3333/his_test?serverTimezone=UTC";
        String username = "root";
        String password = "123456";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static DataSource getOracle() {
        String url = "jdbc:oracle:thin:@192.168.3.35:1521:ORCL";
        String username = "HIS";
        String password = "root";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static DataSource getSqlServer() {
        String url = "jdbc:sqlserver://192.168.0.98:1433;DatabaseName=his_test";
        String username = "sa";
        String password = "lis";
        DataSource dataSource = JdbcUtil.createDataSource(url, username, password);
        return dataSource;
    }

    public static void main(String[] args) {
        //指定数据源
        DataSource ds = getDs();

        // 根据模块更新数据库
        DDLUtil.updateDatabase("com.william.jdbcplus.generator", ds);

        // 更新单表，表不存在则创建表，表存在则更新表结构
        DDLUtil.updateTable(ExcelReport.class, ds);
        DDLUtil.updateTable(ExcelReportDataSource.class, ds);
        DDLUtil.updateTable(ExcelReportDb.class, ds);
        DDLUtil.updateTable(ExcelReportDbField.class, ds);
        DDLUtil.updateTable(ExcelReportDbParam.class, ds);
    }
}
